package com.crx.springbootinit.controller.user;


import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.common.ResultUtils;
import com.crx.springbootinit.model.dto.collect.CollectGiveDTO;
import com.crx.springbootinit.model.dto.collect.CollectPageDTO;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.vo.collect.CollectMyPostVO;
import com.crx.springbootinit.model.vo.collect.CollectPostListVO;
import com.crx.springbootinit.model.vo.love.LoveMyPostVO;
import com.crx.springbootinit.model.vo.love.LovePostListVO;
import com.crx.springbootinit.model.vo.post.PostHomeVO;
import com.crx.springbootinit.service.ICollectService;
import com.crx.springbootinit.utils.ThreadLocalUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 收藏 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user/collect")
@Api(tags = "收藏模块接口")
public class CollectController {

    private final ICollectService collectService;

    @PostMapping
    @ApiOperation("收藏和取消收藏")
    @LogApiAnno(title = "收藏模块", businessType = "POST")
    public BaseResponse<Void> giveCollect(@RequestBody CollectGiveDTO collectGiveDTO){
        collectService.giveCollect(collectGiveDTO);
        return BaseResponse.success();
    }

    @GetMapping("me")
    @ApiOperation("查询收藏我帖子的人列表")
    @LogApiAnno(title = "收藏模块", businessType = "GET")
    public BaseResponse<List<CollectMyPostVO>> queryWhoCollectMyPostList(@RequestHeader String token){
        List<CollectMyPostVO> list = collectService.queryWhoCollectMyPostList(token);
        return ResultUtils.success(list);
    }

    @GetMapping("list")
    @ApiOperation("查询我收藏的帖子列表")
    @LogApiAnno(title = "收藏模块", businessType = "GET")
    public BaseResponse<List<PostHomeVO>> queryMyCollectList(){
        Long userId = ThreadLocalUtil.get("userId");
        List<PostHomeVO> list = collectService.queryMyCollectList(userId);
        return ResultUtils.success(list);
    }

    @GetMapping("count")
    @ApiOperation("查询我的获收藏数量")
    @LogApiAnno(title = "收藏模块", businessType = "GET")
    public BaseResponse<Long> getCollectMyCount(@RequestHeader String token){
        Long count = collectService.getCollectMyCount(token);
        return ResultUtils.success(count);
    }



}
